package com.ruoyi.web.controller.blog;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.blog.domain.TBlogContent;
import com.ruoyi.blog.service.ITBlogContentService;

/**
 * 博客正文Controller
 * 
 * @author yang
 * @date 2021-11-15
 */
@RestController
@RequestMapping("/blog/content")
public class TBlogContentController extends BaseController
{
    @Autowired
    private ITBlogContentService tBlogContentService;

    /**
     * 查询博客正文列表
     */
    @PreAuthorize("@ss.hasPermi('blog:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBlogContent tBlogContent)
    {
        startPage();
        List<TBlogContent> list = tBlogContentService.selectTBlogContentList(tBlogContent);
        return getDataTable(list);
    }

    /**
     * 导出博客正文列表
     */
    @PreAuthorize("@ss.hasPermi('blog:content:export')")
    @Log(title = "博客正文", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBlogContent tBlogContent) throws IOException
    {
        List<TBlogContent> list = tBlogContentService.selectTBlogContentList(tBlogContent);
        ExcelUtil<TBlogContent> util = new ExcelUtil<TBlogContent>(TBlogContent.class);
        util.exportExcel(response, list, "博客正文数据");
    }

    /**
     * 获取博客正文详细信息
     */
    @PreAuthorize("@ss.hasPermi('blog:content:query')")
    @GetMapping(value = "/{contentId}")
    public AjaxResult getInfo(@PathVariable("contentId") Long contentId)
    {
        return AjaxResult.success(tBlogContentService.selectTBlogContentByContentId(contentId));
    }

    /**
     * 新增博客正文
     */
    @PreAuthorize("@ss.hasPermi('blog:content:add')")
    @Log(title = "博客正文", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBlogContent tBlogContent)
    {
        return toAjax(tBlogContentService.insertTBlogContent(tBlogContent));
    }

    /**
     * 修改博客正文
     */
    @PreAuthorize("@ss.hasPermi('blog:content:edit')")
    @Log(title = "博客正文", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBlogContent tBlogContent)
    {
        return toAjax(tBlogContentService.updateTBlogContent(tBlogContent));
    }

    /**
     * 删除博客正文
     */
    @PreAuthorize("@ss.hasPermi('blog:content:remove')")
    @Log(title = "博客正文", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contentIds}")
    public AjaxResult remove(@PathVariable Long[] contentIds)
    {
        return toAjax(tBlogContentService.deleteTBlogContentByContentIds(contentIds));
    }
}
